var django_urls = {
	{% for k, v in urls.items %}{% if k %}
	'{{ k }}': '{{ v|safe }}',
	{% endif %}{% endfor %}
	__empty: ''
};

function reverse(name, params) {
	var url, key;
	if(!django_urls[name]) {
		throw "Reverse for "+name+" not found.";
	}
	url = django_urls[name];
	for(key in params) {
		url = url.replace(new RegExp('\\(\\?P<'+key+'>[^)]*\\)'), params[key]);
	}
	if (url.charAt(0) == '^') {
		url = url.substr(1);
	}
	if (url.charAt(url.length-1) == '$') {
		url = url.substr(0, url.length-1);
	}
	if (url.match(/\(?P<[^>]*>[^)]*\)/)) {
		throw "Invalid params to "+name+".";
	}
	return base_url+url;
};

